﻿create PROCEDURE Sync.SP_LoanFeasabilityStudy_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanFeasabilityStudyID],
		g.[LoanID],g.[FeasabilityStudyDate],g.[RevenueAmount],g.[CostAmount],g.[ProfitAmount],g.[ReturnOnInvestmentPercent],g.[LoanAmount],g.[LoanPaymentPeriod],g.[LoanPaymentMethodID],g.[Notes],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanFeasabilityStudy] g RIGHT JOIN Sync.LoanFeasabilityStudy_Tracking t  
    ON t.LoanFeasabilityStudyID = g.LoanFeasabilityStudyID 
    join [CustomerLoans] cl
		on g.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END














